<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
>
<head>
    <!-- 设置页面的 基本路径，页面所有资源引入和页面的跳转全部基于 base路径 -->
    <base th:href="${#request.getContextPath()}+'/'">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>

    <script type="text/javascript" th:src="@{/lib/html5shiv.js}"></script>
    <script type="text/javascript" th:src="@{/lib/respond.min.js}"></script>


    <link rel="stylesheet" type="text/css" th:href="@{/h-ui/css/H-ui.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/css/H-ui.admin.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/Hui-iconfont/1.0.8/iconfont.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/skin/default/skin.css}" id="skin"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/css/style.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/bootstrap/css/bootstrap.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/bootstrap-table/bootstrap-table.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}"/>

    <script type="text/javascript" th:src="@{/lib/DD_belatedPNG_0.0.8a-min.js}"></script>
    <script>DD_belatedPNG.fix('*');</script>

    <title>医生排班管理</title>
</head>
<body>
<nav class="breadcrumb" style="margin-bottom: 5px"><i class="fa fa-cog"></i> 医生排班管理 <span
        class="c-gray en">&gt;</span> 排班管理 <span class="c-gray en">&gt;</span> 排班列表
</nav>
<div class="page-container" style="padding: 0 20px">

    <span id="toolbar" class="l">
        <input type="hidden" id="lastWeek" name="lastWeek">
        <input type="hidden" id="nextWeek" name="nextWeek">
        <input type="hidden" id="thisWeek" name="thisWeek">

        <a href="javascript:;" onclick="last_week()"
           class="btn btn-primary radius">上一周</a>

        <a href="javascript:;" onclick="this_week()"
           class="btn btn-primary radius">这周</a>

        <a href="javascript:;" onclick="next_week()"
           class="btn btn-primary radius">下一周</a>
    </span>

    <div id="operateDiv" style="display: none;">
        <shiro:hasPermission name="doctorScheduling:update">
            <a title="编辑" href="javascript:;" id="dept_edit" value="" onclick="scheduling_edit(this)"
               style="text-decoration:none"><i class="Hui-iconfont"></i></a>
        </shiro:hasPermission>
        <shiro:hasPermission name="doctorScheduling:delete">
            <a title="删除" href="javascript:;" id="dept_delete" value="" onclick="scheduling_del(this)" class="ml-5"
               style="text-decoration:none"><i class="Hui-iconfont"></i></a>
        </shiro:hasPermission>
    </div>

    <table id="dataTable" class="table table-border table-bordered table-bg">
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" th:src="@{/lib/jquery/1.11.3/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/lib/layer/2.4/layer.js}"></script>
<script type="text/javascript" th:src="@{/h-ui/js/H-ui.min.js}"></script>
<script type="text/javascript" th:src="@{/h-ui.admin/js/H-ui.admin.js}"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" th:src="@{/lib/My97DatePicker/4.8/WdatePicker.js}"></script>
<script type="text/javascript" th:src="@{/lib/datatables/1.10.0/jquery.dataTables.min.js}"></script>
<script type="text/javascript" th:src="@{/lib/bootstrap-table/bootstrap-table.js}"></script>
<script type="text/javascript" th:src="@{/lib/bootstrap-table/bootstrap-table-zh-CN.min.js}"></script>


<script type="text/javascript">
    $(function () {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var result=year + '-' + month + '-' + day;

        $("#lastWeek").val(result);
        $("#nextWeek").val($("#lastWeek").val());

        $('#dataTable').bootstrapTable({
            url: 'doctorScheduling/list',//ajax请求的url地址
            pagination: true,
            toolbar: "#toolbar",//顶部显示的工具条（添加和批量删除的）
            contentType: 'application/x-www-form-urlencoded',//条件搜索的时候ajax请求给后台数据的数据类型（条件搜索post提交必须设置）
            search: true,//是否显示搜索框
            pageNumber: 1,//默认的页面 第一页
            pageSize: 10,//默认的每页条数
            pageList: [10, 15, 50, 100],//每页能显示的条数
            sidePagination: "server",//是否是服务器分页，每次请求都是对应的10条数据，下一页发送ajax请求
            paginationHAlign: 'right', //底部分页条
            showRefresh: true, //是否显示刷新按钮

            columns: [ //表格显示数据对应的表头设置，
                [
                    {
                        "title": "医生排班统计表",
                        "halign": "center",
                        "align": "center",
                        "colspan": 14
                    }
                ],
                [
                    {field: 'schedulingId', title: '编号'},
                    {field: 'username', title: '姓名'},
                    {field: 'deptName', title: '科室名称'},
                    {field: 'startDate', title: '每周开始'},
                    {field: 'endDate', title: '每周结束'},
                    {field: 'workDate', title: '时段'},
                    {field: 'monWork', title: '周一'},
                    {field: 'tueWork', title: '周二'},
                    {field: 'webWork', title: '周三'},
                    {field: 'thuWork', title: '周四'},
                    {field: 'friWork', title: '周五'},
                    {field: 'satWork', title: '周六'},
                    {field: 'sunWork', title: '周日'},
                    {
                        field: 'schedulingId',
                        title: '操作',
                        align: 'center',
                        formatter: getOperateBtns

                    }]],
            queryParams: function (params) {
                //此方法在用户分页或者搜索的时候回自动发送ajax请求调用，并把对应的参数传递给后台
                return {
                    pageNum: params.offset / params.limit + 1, //页码
                    pageSize: params.limit, //页面大小
                    keyword: params.search,
                    last:$("#lastWeek").val(),
                    next:$("#nextWeek").val()
                };
            }
        });

    });

    function getOperateBtns(value, row, index) {
        var html = "";
        $("#operateDiv").find("a").each(function () {
            var myA = $(this).clone()
            myA.attr("value", row.schedulingId)
            html += myA.prop("outerHTML") + "&nbsp;&nbsp;&nbsp;&nbsp;";

        });

        return html;
    }

</script>


<script type="text/javascript">

    function last_week() {
        if ($("#lastWeek").val()==0){
            if ($("#nextWeek").val()==0){
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();
                var result=year + '-' + month + '-' + day;
                $("#nextWeek").val(result)
            }
            $("#lastWeek").val($("#nextWeek").val());
        }
        var last=$("#lastWeek").val();
        var da=new Date(last);
        var res=new Date(da- 7 * 24 * 3600 * 1000);
        var y = res.getFullYear();
        var m = res.getMonth() + 1;
        var d = res.getDate();
        var result=y + '-' + m + '-' + d;
        $("#lastWeek").val(result);
        refresh();
    }

    function this_week() {
        $("#lastWeek").val("");
        $("#nextWeek").val("");
        refresh();
    }

    function next_week() {

        if ($("#lastWeek").val()==0){
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var result=year + '-' + month + '-' + day;
            $("#lastWeek").val(result);
        }
        var last=$("#lastWeek").val();
        console.log(last)
        var da=new Date(last);
        var res=new Date(da.getTime()+7 * 24 * 3600 * 1000);
        var y = res.getFullYear();
        var m = res.getMonth() + 1;
        var d = res.getDate();
        var result=y + '-' + m + '-' + d;
        console.log(result);
        $("#nextWeek").val(result);
        $("#lastWeek").val("");
        refresh();
    }

    /*编辑*/
    function scheduling_edit(obj) {
        var schedulingId = obj.getAttribute("value")
        layer.open({
            type: 2,
            title: '修改排班',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ["700px", '500px'],
            content: ['doctorScheduling/doctorSchedulingEdit?schedulingId=' + schedulingId, 'no']
        });
    }

    /*删除*/
    function scheduling_del(obj) {
        var schedulingId = obj.getAttribute("value")
        layer.confirm('确认要删除吗？', function () {

            $.get("doctorScheduling/delete?schedulingId=" + schedulingId, function (data) {

                //操作结果提示
                layer.msg(data.msg, {icon: data.code, time: 1000}, function () {
                    //操作成功刷新数据
                    if (data.code == 1) {
                        refresh();

                    }
                });

            })

        });
    }

    function refresh() {
        $('#dataTable').bootstrapTable('refresh');
    }


</script>
</body>
</html>
